package com.scorpio.baselibrary;

import android.app.Activity;
import android.app.Application;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.os.StrictMode;

import com.scorpio.baselibrary.utils.AppDataUtil;
import com.scorpio.baselibrary.utils.ActivityManagement;
import com.scorpio.baselibrary.utils.ToastUtil;

/**
 * Created by St on 2018/3/19.
 */

public abstract class PoorApplication extends Application {
    protected static PoorApplication instance;

    //当前正在显示的activity
    @Override
    public void onCreate() {
        super.onCreate();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            // android 7.0系统解决拍照的问题
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
            builder.detectFileUriExposure();
        }
        instance = this;
        AppDataUtil.getInstance().init(this);
        ScreenAdapterTools.init(this);
        //监听activity状态
        ActivityManagement.getInstance().register(this);
    }

    //旋转适配,如果应用屏幕固定了某个方向不旋转的话,下面可不写.
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        ScreenAdapterTools.getInstance().reset(this);
    }

    public static PoorApplication getInstance() {
        return instance;
    }
    public void showToast(Activity view, String content) {
        showToast(view,content,ToastUtil.TOAST_SUCCEED);
    }
    public void showToast(Activity view, String content, @ToastUtil.ToastType int toast_type) {
        //app在前台的时候在现实toast
        if (ActivityManagement.getInstance().getActivityCount() != 0) {
            ToastUtil.show(view, content, toast_type);
        }
    }


    public abstract String getRefreshTokenUrl();

    public abstract String getHost();
}
